(function(){
	'use strict';
	var app = angular.module('welcome',[]);
	app.controller('colorSelector',['$http',function($http){
		this.colors = colorLib;
		this.currColor="color2";
		this.partArr = parts;
		this.bidTotalPrice = 0;
		var wel = this;

		this.updateUnitPrice = function(part){
			part.unitPrice = part.lclUnitPrice*(1-part.discount/100);
		};
		this.updateDiscount = function(part){
			part.discount = 100 - ((part.lclUnitPrice-part.unitPrice)/part.lclUnitPrice)*100;
		};
		
		this.setColor = function(color){
			wel.currColor = wel.colors[color];
		};

		this.change = function(index){
			console.log(index);
			alert(index);
		}

		this.updateUnitPrice = function(part){
			part.unitPrice = part.lclUnitPrice*(1-part.discount/100);
		}
		this.updateDiscount = function(part){
			part.discount = (part.unitPrice/part.lclUnitPrice)*100;
		}
		//翻页通过ajax调用取数据更新noval对象从而刷新页面
		this.thumb=function($http){
			var currChapter = wel.noval.ChapterId;
			var nextChapter = currChapter + wel.page;
			var nextOrPreChapterAction = '/nextOrPreChapter.action';
			if (nextChapter > 0) {
				nextOrPreChapterAction += '?capid=' + nextChapter + 'bookId=' + wel.noval.bookId;
			}else{
				nextOrPreChapterAction += 'bookId=' + wel.noval.bookId;
			}
			$http.get(nextOrPreChapterAction).then(
					function(response){
						alert(response.status);
						alert(response.statusText);
						if (response.status == 200) {
							wel.noval = response.data;
						}
					});
		};
	}]);
	
	app.controller('reader',function(){
		
	});

	app.controller('tabs', ['$scope',function($scope){
		$scope.currentTab = 0;
		$scope.tabsInfo = tabArr;

		$scope.switchTab = function(order){
			tabs.currentTab = tabsInfo[order];

		};
	}]);

	var tabArr = [
		  {name:'Home', link:'#Home', order:0},
		  {name:'Customer and Partners', link:'#cp', order:1},
		  {name:'Part and Pricing', link:'#pp', order:2},
		  {name:'Sales Information', link:'#si', order:3},
		  {name:'Special Bid', link:'#sb', order:4}
		];
	
	var colorLib = {1:'color1',2:'color2',3:'color3',4:'color4',5:'color5',6:'color6'};
	var parts = [
	{partNum:'PA3DLL',partDes:'This is a websphere part providing websphere application server',quantity:0,lclUnitPrice:300,unitPrice:300,discount:0,totalPrice:0,order:1},
	{partNum:'MA4DLL',partDes:'This is a Tivoli workload part for providing a job scheduler.',quantity:0,lclUnitPrice:400,unitPrice:400,discount:0,totalPrice:0,order:2},
	{partNum:'TA6DLL',partDes:'This is a DB2 part for providing RDBMS solution.',quantity:0,lclUnitPrice:500,unitPrice:500,discount:0,totalPrice:0,order:3},
	{partNum:'KA8DLL',partDes:'This is a Cognos part for providing data analysis tool.',quantity:0,lclUnitPrice:600,unitPrice:600,discount:0,totalPrice:0,order:4}
	];

})();